import os
from shutil import copyfile

import cv2
import numpy as np

input_1 = '/home/yjy/dataset/IITD-ROI-Ito-bad'
out_1 = '/home/yjy/dataset/IITD-ROI-Ito'


def is_left(file_name):
    return file_name.find('_l_')


def get_pid(file_name):
    return int(file_name[:3])


def get_iid(file_name):
    return int(file_name[-5:-4])


def cp(path_a, file_a, path_b, file_b=None):
    if file_b is None:
        file_b = file_a
    copyfile(os.path.join(path_a, file_a), os.path.join(path_b, file_b))


if __name__ == '__main__':
    files_1 = os.listdir(input_1)
    for ifile in files_1:
        image = cv2.imread(os.path.join(input_1, ifile), cv2.IMREAD_GRAYSCALE)
        th, image_thr = cv2.threshold(image, 70, 1, cv2.THRESH_BINARY)
        white_num = np.sum(image_thr, keepdims=False)
        print(white_num)
        if white_num > 10000:
            cv2.imwrite(os.path.join(out_1, ifile), image)
        else:
            print(ifile)
